package com.trytry.controller;

import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLDecoder;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.HibernateException;
import org.jboss.weld.servlet.ServletApiAbstraction;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.trytry.dao.CommonDao;
import com.trytry.dao.UserDao;
import com.trytry.entity.FlightInfo;
import com.trytry.entity.Page;
import com.trytry.entity.User;
import com.trytry.service.UserService;
@Controller  
@RequestMapping("/user")  
public class SmvcController  {
	@Resource
	private UserService userservice;

	public UserService getUserservice() {
		return userservice;
	}
	public void setUserservice(UserService userservice) {
		this.userservice = userservice;
	}
	@RequestMapping(value = "/ulist")  
	protected @ResponseBody Map<String, Object> list(@RequestParam("start")int start,@RequestParam("limit")int limit,@RequestParam("page")int curpage,@RequestParam("keywords")String keywords) {
		Page p=new Page();
	     Map<String, Object> modelMap = new HashMap<String, Object>(3);
	        try {
				p = userservice.getArticles(start,limit,curpage,"article_3071_f9b459e3387aaaa701389394a0bb0022",keywords);
			} catch (HibernateException e) {
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			}
	        modelMap.put("data", p.getList());  
	        modelMap.put("total", p.getRowCount());
	        modelMap.put("start", start);
	        modelMap.put("limit", limit);  
	        return modelMap;
	}
@Test
	public void test() throws UnsupportedEncodingException, Exception{
	Class.forName("com.mysql.jdbc.Driver");
	Connection c= DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/flight?characterEncoding=UTF-8","root","root");
	PreparedStatement ps=c.prepareStatement("select md5key,title,summary,remarks,href,author,media_type,sentiment_type,reply_count,view_count,channel,words_num,pub_Time,insert_Time,source,last_Modifier,status from article_3071_f9b459e3387aaaa701389394a0bb0022 where status<>2 and title like '%明天%' limit 3");
	ResultSet rs=ps.executeQuery();
	while(rs.next()){
		System.out.println(rs.getString("title"));
	}
}
	
}
